package com.zhangxu.basemvp.ui;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;

import android.os.Bundle;
import android.widget.EditText;

import com.google.gson.Gson;
import com.zhangxu.basemvp.R;
import com.zhangxu.basemvp.base.BaseActivity;
import com.zhangxu.basemvp.bean.UserBean;
import com.zhangxu.basemvp.contract.LoginContract;
import com.zhangxu.basemvp.presenter.LoginPresenterImpl;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 *
 */
public class LoginActivity extends BaseActivity<LoginPresenterImpl> implements LoginContract.View {
    @Override
    protected LoginPresenterImpl createPresenter() {
        return new LoginPresenterImpl(this);
    }

    @Override
    public String getUserName() {
        return et_email.getText().toString();
    }

    @Override
    public String getPassWord() {
        return et_password.getText().toString();
    }

    @Override
    public void loginSuccess(UserBean user) {
        showMessage(new Gson().toJson(user));
    }

    @BindView(R.id.email)
    EditText et_email;
    @BindView(R.id.password)
    EditText et_password;
    public static void actionStart(Context act) {
        Intent intent = new Intent(act, LoginActivity.class);
        act.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.email_sign_in_button)
    public void toLogin() {
        mPresenter.login();

    }
}

